<?php


/**
 * CF_class_com.php includes main auto creation classes
 * This package licenced under GPL
 * @package CFtable
 * @license http://www.gnu.org/licenses/gpl-3.0-standalone.html
 * @copyright Managed Computer Solutions
 */
//  2008-12-19 changed 'showkey' and 'valuekey' to 'showvalue' and 'keyvalue' for drop down and multiple radio options




define("TABLE_EVEN_CLASS","even_row_color");
define("TABLE_ODD_CLASS","odd");



// ----------------------------- Field Spec settings are as below:	
//$fieldspec['<column>'] ['show'] = {'0' = notshown, '1' = show readonly, 'L' = show, use list (manual join), E = editable;
//$fieldspec['<column>'] ['key'] = {1 = key field, 0 of not (or dont include)};
//$fieldspec['<column>'] ['select'] = {'T' = text, 'D' = dropdown select, 'C' = checkbox (for 1 or 0 boolean), 'R' = radiogroup, 'A' = textarea, 'DT' or 'CAL' = calendar for date-time};
//$fieldspec['<column>'] ['filter'] = {1 if value is filtered for, 0 or undefined if not};	
//$fieldspec['<column>'] ['add'] = {1 = include value as input in add box, 0 or undefined = do not };
//$fieldspec['<column>'] ['size'] = size of input field, or columns (cols) for textarea;
//$fieldspec['<column>'] ['rows'] = rows of textarea or listbox (future);
//$fieldspec['<column>'] ['headname'] = {Name to show on column heading or input heading};
//$fieldspec['<column>'] ['keyvalue'] = {array column to use for key in drop-down lists} ;
//For lists, Not needed if columns 'keyvalue' and 'showvalue' are used in array, no need to define these specs;
//$fieldspec['<column>'] ['showvalue'] = {array column to use for shown value in drop-down lists};
//$fieldspec['<column>'] ['rawformat']	= additional html to include inside the input field;
//$fieldspec['<column>'] ['image']	= image file name of image to associate with control (implemetned for calendar);
//$fieldspec['<column>'] ['showdateformat'] = format string for inital display of shown date, using php date formatters;
//$fieldspec['<column>'] ['cal'] ['ifFormat'] = format string of date from database (or whatever) for input to calendar, js date formatters;
//$fieldspec['<column>'] ['cal'] ['align'] = {'T1' Shows calendar above imput control (default), 'B1' shows it below controls};
//$fieldspec['<column>'] ['cal'] ['showsTime'] = {true = show time in calendar below date, false (Default) = show and use calendar for dates only};
//$fieldspec['<column>'] ['cal'] ['singleClick'] = {true = (Default) open calendar with single click, false = double click for calendar};
//$fieldspec['<column>'] ['allowhtml'] = {true:  do not escape html (to allow images, etc), false (or unset by default) escapes using htmlspecialchars)};
//$fieldspec['<column>']['source'] = table name for source table, will be appended to filters to resolve ambiguies with multiple tables
 

include_once "CF_support.php";
// Classes
/**
 * BasicTable is a class to dumping of data from a database in an array.  This basic version makes an HTML output
* @package CFtable
 * @author Chris Tyler
 * @version 1.0
 * @BasicTable is the base class for the an extensable HTML table class for array based data.  This provides data display, sorting, filtering, paging and heading functions
 * @copyright 2007-2008 
 */
class BasicTable {
	/**
	* @var array $valuesarray A 2D array of values, an array of associative row arrays, valuesarray[<row number>][<column heading>]
	*/
	var $valuesarray;
	/**
	* @var array $fieldspec Array describes data and formatting options
	*/	
	var $fieldspec;
	/**
	* @var string $row_status Internal variable for determing odd or even row in table
	*/	
	var $row_status;
	/**
	* @var bool $show_all_rows Set to true to show all rows regardless of fieldspec in basic table
	*/
	var $show_all_rows;
	/**
	* @var string $table_odd_class Set the name of the class to give odd table rows
	*/	
	var $table_odd_class = 'odd_row_color';
	/**
	* @var string $table_even_class Set the name of the class to give odd table rows
	*/	
	var $top_dir = '';
	/**
	* @var string $top_dir Set absolute or relative reference to the base directory (for things in subdirectories)
	*/	
	var $table_even_class = 'even_row_color';	
	/**
	* @var bool $multiselect Set to true to show select row for multiselect form to
     * set one or more rows at once.   This is always false for basic Table
	*/		
	var $multiselect = false; 
	
	/**
	 *  BasicTable Constructor method will form table from spec and values
     * Default will show all columns
     * all checked rows at once.
     * @param array $the_spec  This is fieldspec array.  defaults to show all rows
     * @param array $values array.  This is 2d array by rows
	 */
	function BasicTable( $the_spec = 'all', $values_array = ''){
		$this->values_array = $values_array;
		if(is_array($the_spec)){
			$this->fieldspec = $the_spec;
			$this->show_all_rows = false;
			}
		else{
			$this->show_all_rows = true;
			}
	}
	/**
	 *  set_valuesarray Method will set values array to passed array
     * @param array $dataarray  This is array.  
	 */
	function set_valuesarray($dataarray){
		$this->valuesarray = $dataarray;	
	}	


	
/**
 * Set FieldSpec Function
 * @param array $thespec - The fieldspec array
 * @param array $thespec [<colname>] - Set for each column, as named in the database query used
 * @param array $thespec [<colname>] ['headname'] (opt) - Name to display on the header for the column.  If not there, will use <colname>
 * @param array $thespec [<colname>] [key] - If set (1), this will be used as a key field for record operations
 * @param array $thespec [<colname>] [show] - If set (1), this column will show in displays.  If 0 or unset, column will not appear
 * @param array $thespec [<colname>] [select] - How to display editable boxes: {T = Text Input, C = Check box (0 or 1), D = drop down) 
 * @param array $thespec [<colname>] [list] = array of values (showvalue, keyvalue) to use in drop-down.  Array is of form:  valueslist [<index integer>][<keyvariablename>][<showvariablename>] Where defaults are keyvariablename = 'keyvalue' showvariable='showvalue' unless re-assigned
 * @param array $thespec [<colname>] [showvalue] - (opt)  Re-assignes the <keyvariablename> to the string specified, instead of 'keyvalue'
 * @param array $thespec [<colname>] [keyvalue] - (opt) Re-assignes the <showvariablename> to the string specified, instead of 'showvalue'
 * @param array $thespec [<colname>] [sort] - Specifies if row header will sort or not, {true, false, (or undefined)}
 * @param array $thespec [<colname>] [filter] - Specifies if row is filtered. if set= 'keyword', then will  bet textbox for LIKE '%keyword%' search.  If set (= 1, but not specific setting ), then will filter using spec from edit criteria ([select],[list],)
 */		
	function set_fieldspec($thespec){
		$this->fieldspec = $thespec;
	}	
	/**
	 *  clear_keys_strings Method will clear keys array.  Placehoder, to be expanded
	 */
	function clear_keys_strings(){}
	/**
	 *  make_key_string Method will set keys array.  Empty, Placehoder, to be expanded
	 */
	function make_key_string($col_name, $currentvalue){}
	

	/**
	* function to make start of row.  Override / extend
	* @param int $row_num This is the row number of the dataset
	* @param string $key_string This is the string of key values, defined by make_key_string function
	* @return string Row begining 
	*/
	function make_row_start($row_num){
		if($this->row_status == 'even'){
			$this->row_status = 'odd';
			$rowstart .= "<tr class=\"$this->table_odd_class\">";			
		}
		else{
			$this->row_status = 'even';
			$rowstart .= "<tr class=\"$this->table_odd_class\">";			
		}

		return $rowstart;
	}
	/**
	 *  make_row_end Method will set create table row end.  returns end tag, to be expanded
	* in derived classes.
	* @param int $row_num Current row number
	 */
	function make_row_end($row_num){
		return "</tr>\n";	
	}
	/**
	 *  make_rowval Method will set create table row value.  Returns value in td.
	 * Expanded in derived classes.
	 * @param string $currentvalue Value to show
	 * @param string $col_name NAme of column to show
	 * @param string $current_text Starting text, not used, expend in derived clases
	 */	
	function make_rowval($currentvalue, $col_name, $current_text){
		return "<td>$currentvalue</td>";
	}
	/**
	 *  on_start_row Method will execute when row is started.  Placehoder, to be expanded
	 */	
	function on_start_row($row_num){
	}

	
	/**
	 * maketable will return the table text from the class, for use as the body of a table
	 * @return string
	 */
	function maketable(){
		//print_r($this->fieldspec);
		if(!empty($this->valuesarray)){
		foreach($this->valuesarray as $row_num => $currentrow) {	
			$this->on_start_row($row_num);
			$this->clear_keys_strings();  // Clear keys_string
			$row_text = '';
			//$col_num = 0; // count column numbers incase of csv or difference in row_val function
			
			// 2010 CT Test interate on fieldspec instead of valuesarray
			
			//foreach ($currentrow as $col_name => $currentvalue) {
			foreach ($this->fieldspec as $col_name => $thefield){
				$currentvalue = $currentrow[$col_name];
				// 2010 end new rewrite
						
                if(!$thefield['allowhtml']){
                    $currentvalue = htmlspecialchars($currentvalue,ENT_QUOTES);
                    }
				
				if(!empty($thefield['key'])){
					$this->make_key_string($col_name, $currentvalue);
				}
				
				$makefunction = 'make_' . $col_name;
				if(method_exists($this,$makefunction)){	
					$rawvalue = $this->valuesarray[$row_num][$col_name];
					$currentvalue = $this->$makefunction($currentvalue);
				}
				
				if($this->show_all_rows or (!empty($thefield['show']))){
					$row_text .= $this->make_rowval($currentvalue, $col_name, $row_text);

				}// end show field
				
			
			} // end for each colucm in fieldspec
			//}// End for each column (value) in row
			$table_text .= $this->make_row_start($row_num) . $row_text . $this->make_row_end($row_num) ; 
		}// end for each row
		}// end is not empty valuesarray
		return $table_text;	
	
	}
    
	/**
	 * make_simple_heading will return a heading row of the column name, in order of fieldspecs presented in fields definition
	 * @return string
	 */
	function make_simple_heading(){
		if($this->multiselect){
			$headtext .= '<th>Select</th>';
		}
		foreach($this->fieldspec AS $col_name => $colspec){
			$headtext .= '<th>';
			(empty($colspec['headname']))?$headtext .= $col_name: $headtext .= $colspec['headname'] . "</th>\n";
			}
		return $headtext;
	}



	
} // End BasicTable Class



/**
 * csvTable is a class to output CSV from an array, usually returned form a Database
* @package CFtable
 * @author Chris Tyler
 * @version 1.0
 * @copyright 2007-2008 
 */
Class csvTable Extends BasicTable{

	// public vars
	var $msg_no_data = 'There is no data avalible for this csv';

	// private vars
	var $is_first_col = true;	
	
	var $multiselect = false;
	
	// Functions
	
	function make_row_start($row_num){

	}
	/**
	 * make_row_end for CSV - insert line end, and reset first coumn bool
	 * @return string
	 */
	function make_row_end($row_num){
		$this->is_first_col = true; // carefull - that this is always run AFTER the rows are made!	
		return "\n";

	}
	/**
	 * make_rowval for CSV - escape the text properly, and only insert a , after the first value
	 * @return string
	 */	
	function make_rowval($currentvalue, $col_name, $current_text){
		if($this->is_first_col){
			$this->is_first_col = false;		
			return csvEscapeText($currentvalue);
			
			}
		else{
			return ',' . csvEscapeText($currentvalue);
			}
	}
	/**
	 * maketable will return the a heading line  (+ line return)  for the csv based on the fieldspec
	 * @return string
	 */		
	function make_heading(){
		if(!is_array($this->fieldspec)){
			return;
		}
		$after_first_col = false;
		if($this->multiselect){
			$headtext .= 'Select';
		}
		foreach($this->fieldspec AS $col_name => $colspec){
			if($after_first_col){
				$headtext .= ',';
				}// if after_first_col = true, then add the comma.  if it is false, then don't.
				
			if(empty($colspec['headname'])){
				$headtext .= csvEscapeText($col_name);
				}
			else{
				$headname = $colspec['headname'];
				$headtext .= csvEscapeText($headname);
				}
			$after_first_col = true;
			}
		return $headtext . "\n";

	}
	/**
	 * export_to_csv will export the csv as a file to the browser.  It will use the current fieldspec and values array.
	 *@param string filename - the full filename (with extension) to use when returning the data.
	 *@param use_heading - Set to true to include a heading (from make_heading) as the first line of the file
	 * @return string
	 */
	function export_to_csv($filename, $use_heading = false){
		if($this->valuesarray){
			if($use_heading){
				$heading = $this->make_heading();
			}
			$csv_file_text = $heading . $this->maketable();
			
			header("Content-type: application/x-msdownload");
			header("Content-Disposition: attachment; filename=$filename");
			header("Pragma: no-cache");
			header("Expires: 0");
			echo $headers.$csv_file_text;
		}
		else{
			print $this->msg_no_data;
			}
	
	} // end export_to_csv


} // end Class csvTable



/**
 * CFtable is a class to simplfy creation of Databse CRUD (Create Remove Update Delete) Tables
* @package CFtable
 * @author Chris Tyler
 * @version 1.0
 * @CFtable is the base class for the an extensable HTML table class for array based data.  This provides data display, sorting, filtering, paging and heading functions
 * @copyright 2007-2008 
 */

class CFtable extends BasicTable{
	/**
	* @var string $table_name Defines name of the table (associated elements)
	*/	
	var $table_name = 'datatable';
	/**
	* @var string $table_start Defines start of the string for use in HTML data output.  (unused)
	*/
	var $table_start;
	/**
	* @var string $table_text String of HTML for output as table
	*/	
	var $table_text;
	/**
	* @var string $selfpage The name of the page, usualy set by $_SERVER['SELF']
	*/
	var $selfpage;
	/**
	* @var array $referstrng (not used)
	*/
	var $referstring;	
	// persistant info:  The ordervar, filtersvar, and liststartvar, listsizevar will hold the state of the ordering and filters
	// as shown on the page when the list is shown.
	// set this variable for order when re-ording this query with the headers

	//var $filtersvar = 'cfFilters'; // holds the string of all set filters, ready for append to url
	/**
	* @var string $liststartvar String used for list start variable
	*/	
	var $liststartvar = 'cfListStart'; 
	/**
	* @var string $liststartvar String used for list size variable
	*/		
	var $listsizevar = 'cfListSize';
 	/**
	* @var bool $use_ms_divform switch to use div form instead of table for multiselce row (default false, use table)
	*/
	var $use_ms_divform = false;
 
 
	/**
	* @var string $filterprefix prefix for filtered variables (column name used)
	*/
	var $filterprefix = 'flt_';
	/**
	* @var string $editvarprefix prefix for filtered variables (column name used)
	*/
	var $editvarprefix = '';


	// ----------------------------------- Variables changed by functions
	/**
	* @var string $row_status String used row status, even or odd
	*/    
	var $row_status;	
	/**
	* @var string $keys_url_edit Internal String used to show keys and values as row pamamerter
	*/	
    var $keys_url_edit;
	/**
	* @var string $keys_url_edit Internal String used to show keys and values as row pamamerter
	*/
    var $keys_url_act;
	/**
	* @var string $addtype String used to track type of add form to create.  {'button','new' 'entires'}
	*/    
	var $addtype = 'button'; // button, keys, are options
	/**
	* @var string $keys string for keys as pulled from Request for edit page
	*/  	
    var $keys;
 	/**
	* @var string $ap_page afterprocesspage Direct processor to load thispage after processing
	*/
    var $ap_page;
	/**
	* @var array $filters Holds fitlers as array filers[<column>] = <value> filled by get_filter_vals().  This expects filter variables form the $_REQUEST or from the $_SESSION if saved (pass empty to clear).  Uses prefix determined by $filterprefix
	*/
	var $filters; 
	/**
	* @var bool $multiselect Determines whether to  implement multi-change logic on table
	*/
	var $multiselect = true;
	/**
	* @var string $actval_prefix prefix for add variables (column name used), must be set the same in processing class or logic
	*/
    var $actval_prefix = '';
	/**
	* @var string $keys_uid keys as semicolon (;) delimited fields per row
	*/    
	var $keys_uid;
	/**
	* @var bool $show_filter_submit show sumbit filter (Default true)
	*/   	
    var $show_filter_submit = true;
	/**
	* @var string $show_filter_value string to show on filter button (default 'Apply')
	*/   	
	var $show_filter_value = 'Apply';
	/**
	* @var string $addmarkup string of markup to put in add form for other hidden fields, etc.
	*/  	
	var $addmarkup;
	
	
// Sort variables
	var $new_order;
	var $cur_order;
	var $pagename;
	var $new_dir;
	var $cur_dir;
	var $orderstring;
	var $ordervar = 'order';

//paging variables
	var $startat;
	var $numrows;
	var $post_rowlimit;
	var $startatvar = 'startat';
	var $numrowsvar = 'numrows';
	var $default_row_limit = 10;
	var $nextpagestart;
	var $prevpagestart;
	var $rowsmax = NULL; // default Null for unknown
	//var $oracle_post_rowlimit;
	//var $oracle_pre_rowlimit = "SELECT * FROM ( SELECT thequery.*, rownum rnum from ( ";
	//var $pgsql_post_rowlimit;
	//var $fbird_fix_rowlimit;
	

// ---------------------------------FUNCTIONS---------------------------------
// ---------------------------------Public Functions--------------------------
	
/**
 * Constructor.  Override / extend
 * @param array $thespec - The fieldspec array
 * @param array $dataarray - The data array, data[<rownumber>][<column_name>]
 */		
	function CFtable( $thespec = '', $dataarray= '', $allowspec = 'rde' ){
		$this->fieldspec = $thespec;	
		$this->valuesarray = $dataarray;
		
		$this->selfpage = $_SERVER['PHP_SELF'];
		$this->ordervar = 'order';	
	}
	
	function set_name($name){
		$this->table_name = $name;	
	}
	
	function set_ordervar($newordervar){
		$this->ordervar = $newordervar;
	}	
	
	function set_selfpage($newpage){
		$this->selfpage = $newpage;
	}	
	


	/**
	 * make_simple_heading will return a heading row of the column name
	 * @return string
	 */
	function make_simple_heading(){
	if($this->multiselect){
		$headtext .= '<th>Select</th>';
	}
	foreach($this->fieldspec AS $col_name => $colspec){
		$headtext .= '<th>';
		(empty($colspec['headname']))?$headtext .= $col_name: $headtext .= $colspec['headname'] . "</th>\n";
		}
	return $headtext;
	}

	/**
	 * make_sort_heading will return a heading where clicking on the colum name will sort by the column
	 * This requiresthe page to reload to sort the the column name through the variable specified by
	 * set_ordervar().  The return page is set in set_selfpage().
	 * @return string
	 */
	function make_sort_heading(){
	if($this->multiselect){
		$headtext .= '<th>Select</th>';
	}
	foreach($this->fieldspec AS $col_name => $colspec){
		if(!empty($colspec['show'])){
		$headtext .= '<th>';
		(empty($colspec['headname']))?$name = $col_name: $name = $colspec['headname'] . "</th>\n";
		
		if($colspec['sort'] == true){
			$headtext .= "<a href=\"$this->selfpage?$this->ordervar=$col_name$referstring\">$name</a>";
		}
		else{
			$headtext .= $name;
		}
		$headtext .= "</th>";
		} // end if shown
		}// end foreach
		
		// add cells for actions
		if($this->allow_delete){$headtext .= "<th></th>";}
		if($this->allow_save){$headtext .= "<th></th>";}
		if($this->allow_edit){$headtext .= "<th></th>";}
				
	return $headtext;
	}	


	/**
	 *
     * @make_form will create an editable form for the feildset
	 *
	 */
     function make_form($method = 'get'){
        if(!empty($this->valuesarray)){
    		$outtext = "<form name='form_input' method='$method' action='$this->actionpage'>\n";
    		$currentrow = $this->valuesarray[1];

			foreach ($currentrow as $col_name => $currentvalue) {
                if($this->fieldspec[$col_name]['show'] == 'E'){
                    (empty($this->fieldspec[$col_name]['headname']))?$elements[$col_name]['heading'] = $col_name: $elements[$col_name]['heading'] = $this->fieldspec[$col_name]['headname'];
                    $elements[$col_name]['input']= MakeEditField($this->fieldspec[$col_name],$col_name,$currentvalue,$chgname,$col_name,false,$this->top_dir);
                }
             }

		 //print_r($elements);
		 $outtext .= $this->make_element_div_set($elements, "class='header'", "class='input'");
		 $outtext .= $this->make_keys_hidden();
		 $outtext .= "\n<div class='controls'><input type='submit' name='mode' value='Save'></div>\n";
		  //$outtext .= "</div>\n";
	 return $outtext;
	 }
	}


	/**
	 *  make_pageform  Method will produce the "First, Previous <-- --> Next " line for
     * naviating paginated records
     *
	 */
	function make_pageform(){
			return $this->pageform;
	}
	
	function make_query_post_rowlimit(){
	return $this->post_rowlimit();
	
	}

	/**
	 *  make_multi_act_row  Method will produce a multipe-action row to change
     * all checked rows at once.
     * @param string $method {'get' or 'post'} for form return method
     *
	 */
	function make_multi_act_row($method = "get"){
		$none_entry[1]['keyvalue'] = '';
		$none_entry[1]['showvalue'] = '';
	

		$msrow .= "<form name='ms_form'  id='" . $this->table_name . "_ms_form' action='$this->actionpage' method='$method'>";

        //$count = 0;
		foreach($this->fieldspec AS $col_name => $colspec){
            if($colspec['show'] == 'E'){
                (empty($colspec['headname']))?$elements[$col_name]['head'] = $col_name: $elements[$col_name]['head'] = $colspec['headname'] ;
                $elements[$col_name]['head'] .= "<input type='checkbox' name='IS_CHG_$col_name' value='1'>";
                $elements[$col_name]['body'] = MakeEditField($this->fieldspec[$col_name],  $col_name, '', '', 'MS_' . $col_name, $none_entry,$this->top_dir);

                //$count ++;
			}
		}	// end foreach fieldspec
		$elements['MS_Change']['head'] = 'Change Selected';		
		$elements['MS_Change']['body'] = "<input type='hidden' name='mode'>";
		$elements['MS_Change']['body'] .= "<input type='button' name='multiedit' value='Change ' onClick='doMultiChange()' >";
		//$count ++;
		$elements['MS_Delete']['head'] = 'Delete Selected';
        $elements['MS_Delete']['body'] = "<input type='button' name='mutlidelete' value='Delete' onClick='doMultiDelete()' > ";
	    $elements['MS_Delete']['body'] .= "<input type='hidden' name='seltrans' id='seltrans'>";
		//$count ++;
        //$elements[$count]['body'] = "<input type='button' name='setmulti' value='Set' onClick='get_selections()' >";

		// Need to change the following name to something descriptive but unique and matches JS.

		if($this->use_ms_divform){
			$msrow .= $this->make_form_set($elements,"class='ms_head_class'","class='ms_row_class'");			
		}else{
			$msrow .= $this->make_element_set($elements,"class='ms_head_class'","class='ms_row_class'");
		}
        //
	
		$msrow .= "<input type='hidden' name='rqkeyvariables' value='" . $this->make_keyvariables() . "' />\n";
	
	
	
        $msrow .= "</form>\n";

	return $msrow;
	}

   	/**
	 *  make_keyvariables  Method will output a comma delimited list of variables (columns) which are keys from fieldspec
	 */
	function make_keyvariables(){
		$aftercomma = '';
		foreach($this->fieldspec as $col_name => $colspec){
			if(!empty($this->fieldspec[$col_name]['key'] )){
				$keyvariables .= $aftercomma . $col_name;
				$aftercomma = ',';
			}
		}
		return $keyvariables;
	}
	
	
   	/**
	 *  make_apply_all  Method will output the Select All and Clear All buttons
	 */
	function make_apply_all(){
		return "\n<input type='button' value='Select All' onClick='select_by_name()'><input type='button' value='Clear All' onClick='unselect_by_name()'>\n";
	
	}


	
/**
 * function to make start of row.  Override / extend
 * @param int $row_num This is the row number of the dataset
 * @param string $key_string This is the string of key values, defined by make_key_string function
 * @return string Row begining 
 */
	function make_row_start($row_num){
		if($this->row_status == 'even'){
			$this->row_status = 'odd';
			$rowstart .= "<tr class=\"$this->table_even_class\">";			
		}
		else{
			$this->row_status = 'even';
			$rowstart .= "<tr class=\"$this->table_odd_class\">";			
		}
		if($this->multiselect){
			$rowstart .= "<td>" . $this->make_multiselectCB() . "</td>";
		}	
		return $rowstart;
	}

	function make_multiselectCB(){
		return "<input type='checkbox' name='" . $this->table_name . "_addto_ms' value='" . $this->keys_uid . "' >";
	
	}	
	
	function make_row_end($row_num){
		return "</tr>\n";
	}
	
	function make_rowval($value,$column){
		$row_text .= "<td>";
		$row_text .= $value;
		$row_text .= "</td>";
		return $row_text;
			
	}

	function clear_keys_strings() { 
		$this->keys_url_edit = '';
        $this->keys_url_act = '';
		$this->keys_uid = '';
	}
	





	/**
	 * get_filter_vals() will recieve the filter variables from Session or request
     * and set them in the filters array.
     * To clear filter, pass in a request with the filter set to nothing
     * ($variable1=&variable2=)
     * Filters are kept as filter [filter variable name][value]
     * Where filter variable name is filter prefix ($this->filterprefix) . variable name
	 */
	function get_filter_vals($method = 'req'){
		//print "IN GET FILTER VALS";
		foreach($this->fieldspec AS $col_name => $colspec){
			//if(isset($colspec['filter'])){
				// CT 20090618 take out if this works
				//print "Getting $col_name Filter";
                $currentvalue = GetPersistent($this->filterprefix . $col_name,$method);
                if(!is_null($currentvalue)){
                    $this->filters[$this->filterprefix . $col_name]['var'] = $col_name;
                    $this->filters[$this->filterprefix . $col_name]['val'] = $currentvalue;
                   // $this->filters[$this->filterprefix . $col_name]['source'] =
                }else{
					unset($this->filters[$this->filterprefix . $col_name]['var']);
					unset($this->filters[$this->filterprefix . $col_name]['val']);
				}
           // }
        }
    }

	/**
	 * get_filter_pvals() will recieve the filter variables from Session or request
     * and set them in the filters array.  This uses the page specific filters storage
     * To clear filter, pass in a request with the filter set to nothing
     * ($variable1=&variable2=)
     * Filters are kept as filter [filter variable name][value]
     * Where filter variable name is filter prefix ($this->filterprefix) . variable name
	 */	
	function get_filter_pvals($method = 'req'){
		foreach($this->fieldspec AS $col_name => $colspec){
			//if(isset($colspec['filter'])){
                $currentvalue = GetPagePersistent($this->filterprefix . $col_name,$method);
                if(!is_null($currentvalue)){
                    $this->filters[$this->filterprefix . $col_name]['var'] = $col_name;
                    $this->filters[$this->filterprefix . $col_name]['val'] = $currentvalue;
                   // $this->filters[$this->filterprefix . $col_name]['source'] =
                }else{
					unset($this->filters[$this->filterprefix . $col_name]['var']);
					unset($this->filters[$this->filterprefix . $col_name]['val']);
				}
            //}
        }
    }	
	
	

	
	

//Set filter and Session value - generic	
function set_filter_val($col_name, $filter_value, $page_name = ''){
	if($page_name == ''){
		$page_name = $this->selfpage;
	}
	$this->filters[$this->filterprefix . $col_name]['var'] = $col_name;
	$this->filters[$this->filterprefix . $col_name]['val'] = $filter_value;
	$_SESSION[$this->filterprefix . $col_name] = $filter_value;
}

//UnSet filter and Session value - generic	
function un_set_filter_val($col_name, $page_name = ''){
	if($page_name == ''){
		$page_name = $this->selfpage;
	}
	unset($this->filters[$this->filterprefix . $col_name]);
	unset($_SESSION[$this->filterprefix . $col_name]);
}
//Set filter and Session value - page specific	
function set_filter_pval($col_name, $filter_value, $page_name = ''){
	if($page_name == ''){
		$page_name = $this->selfpage;
	}
	$this->filters[$this->filterprefix . $col_name]['var'] = $col_name;
	$this->filters[$this->filterprefix . $col_name]['val'] = $filter_value;
	$_SESSION[$page_name]['filters'][$this->filterprefix . $col_name] = $filter_value;
}

//UnSet filter and Session value - page specific	
function un_set_filter_pval($col_name, $page_name = ''){
	if($page_name == ''){
		$page_name = $this->selfpage;
	}
	unset($this->filters[$this->filterprefix . $col_name]);
	unset($_SESSION[$page_name]['filters'][$this->filterprefix . $col_name]);
}


	
	/**
	 * make_query_filter will create a query filter according to fieldspec settings, Request input, and Session data
	 * 
	 */
	function make_query_filter(){

		if(!empty( $this->filters)) {
            $tabledot = '';
			foreach($this->filters AS $filtername => $filter){
	// CT 2009-10-27 Added ' AND (!empty($this->fieldspec[$currentvar]['filter']))
	// CT 2009-11-07 Added this as new if stmt to the correct line a few lines below
                $currentvar = $filter['var'];
				if(!empty($this->fieldspec[$currentvar]['filter'])){
					if(isset($this->fieldspec[$currentvar]['source'])){
							$tabledot = $this->fieldspec[$currentvar]['source'] . '.';
						}
					$flt_text .= " AND $tabledot" . $filter['var'] . " = '" . $filter['val'] . "' ";
				}
			}	
		}
	
	return $flt_text;
	}

	/**
	 *
     * @make_element set will create a line of headed elements arranged in a table
     * from an input of an element_set array.  Each row has element_name and value
     * @param array elements An array with [body] and [head] parts where head
     * elements['head'] is the title and elements['body'] is what to put in the cell
     * @param string $headset Settings for heading elements (class name, etc)
     * @param string $bodyset Settings for body elemetns (class naem, etc)
	 *
	 */
    function make_element_set($elements, $headset, $bodyset){

        if(is_array($elements)){
        foreach ($elements AS $current){
            $headtext .= "<th>" . $current['head'] . "</th>\n";
            $bodytext .=  "<td>" . $current['body'] . "</td>\n";
        }
        }
        return "<tr $headset>$headtext </tr> <tr $bodyset>$bodytext</tr>";
    }

	
	
    function make_form_set($elements, $headset, $bodyset){

        if(is_array($elements)){
			foreach ($elements AS $col_name=>$current){
				$formtext .= "<div class='ms_$col_name' ><label for='$col_name'>" . $current['head'] . "</label>\n" . $current['body'] . "</div>\n";
			}
        }
        return "<fieldset>\n$formtext</fieldset>\n";
    }	
	

	/**
	 *
     * @make_element_div_set set will create a set of div for use as a form
     * from an input of an element_set array.  Each row has element_name and value
     * @param array elements An array with [body] and [head] parts where head
     * elements['head'] is the title and elements['body'] is what to put in the cell
     * @param string $headset Settings for heading elements (class name, etc)
     * @param string $bodyset Settings for body elemetns (class naem, etc)
     * @param string $id Settings for name of the div set
	 *
	 */
    function make_element_div_set($elements, $headset, $bodyset){
        foreach ($elements AS $name=>$current){
            $outtext .= "<div id='entry_$name' class='entries'>\n";
            foreach($current AS $key=>$value){
            
                $outtext .= "<div class='$key'>\n $value </div>\n";
                }
            $outtext .= "</div>\n";
         }
         
        return $outtext;
    }
	



	function get_edit_keys(){
	//for each column which is a key, get the key and set the keys variable array
	foreach ($this->fieldspec as $col_name => $colspec){
		if((!empty($colspec['key'])) AND (isset($_REQUEST[$col_name])) AND ($_REQUEST[$col_name] != '') ){
			$this->keys[$col_name] = $_REQUEST[$col_name];
			}
		}
		//print_r ($this->keys);
	}
	
	
	/**
	 * function to make key string.  Override / extend
	 * @param int $col_name This is the column name for the key value
	 * @param string $currentvalue This is the value of the key
	 * @param int $firstrow This is 1 for the first row, 0 afterwards for special punctuation
	 * @return string keystring
	 */	
    function make_key_string($col_name, $currentvalue, $firstrow = 0){
		if(empty($this->keys_uid)){
			$this->keys_uid =  "$currentvalue";
	
		}
		else{
			$this->keys_uid .=  ",$currentvalue";
		}
		$this->keys_hidden .= "<input type='hidden' name='$col_name' value='$currentvalue'>";
		//parent::make_key_string($col_name, $currentvalue);
		$this->keys_url_edit .= "&$this->editvarprefix" . "$col_name=$currentvalue";
        $this->keys_url_act .= "&$col_name=$currentvalue";
		
	}
	
	function make_keys_clause(){
		foreach($this->fieldspec as $col_name => $colspec){
			if(!empty($this->fieldspec[$col_name]['key'] )){
				if(isset($this->keys[$col_name])){ // check if defined and exists in keys array
					$outtext .= " AND $col_name = '" . $this->keys[$col_name] . "' ";
				}else{
					$outtext .= " AND 0 "; // Not all specified keys were defined, so return 0 to kill any results form query
				}
			}
		}
		return $outtext ;
	}
	
	function make_keys_hidden(){
		foreach($this->fieldspec as $col_name => $colspec){
			if(!empty($colspec['key'] )){
				if(isset($this->keys[$col_name])){ // check if defined and exists in keys array
					$outtext .= " <input type='hidden' name='$col_name' value='" . $this->keys[$col_name] . "'> ";
				}
			}
		}
		return $outtext;
	}
	
	
	//MOVE TO CF_FILTER
	/**
	 *
	 * make_filters_box  Method to create a fitlers box which will show each editable
	  * value in it's own text entry or drop-down box for filtering
	 * @param string $method Form Method (get or post)
	 *
	 */
    function make_filters_box($method = 'get'){
        $none_entry[1]['keyvalue'] = '';
		$none_entry[1]['showvalue'] = '';
		$showbox = false;
		
		
		$filterbox .= "<table class='filterbox'><form name='filters_box' action='$this->selfpage' method='$method'>\n";
        $count = 1;
        foreach($this->fieldspec AS $col_name => $colspec){
			if((!empty($colspec['filter']) ) AND (!empty($colspec['showfilter']))){ // insert AND 
				$showbox = true;
                if(!empty($colspec['headname'])){
                    $elements[$count]['head'] = $colspec['headname'] ;
                }else{
                    $elements[$count]['head'] =  $col_name;
                }
				$filtername = $this->filterprefix . $col_name;
                $elements[$count]['body'] = MakeEditField($this->fieldspec[$col_name], $filtername, $this->filters[$filtername]['val'], 'this.form.submit()', $filtername, $none_entry,$this->top_dir);
                $count ++;
			}// end colpsec filter set
        }// end foreach field
        $filterbox .= $this->make_element_set($elements, "class='filter_head'","class='filter_head'");
        if($this->show_filter_submit){
            $filterbox .= "<tr><td colspan='$count' > <input type='hidden' name='$this->startatvar' value='0'> <input type='submit' id='refresh' name='refresh' value='$this->show_filter_value'></form> </td></tr>\n";
        }else{
            $filterbox .= "</form>";
         }
         $filterbox .= "</table>";
	if($showbox){	 
		return $filterbox;
	}
	else{
		return '';
	}
    }

// NOTE:  Add procedure adds whatever it is passed.  It is up to the add form to send the correct items.  If something is filterd, it needs to be sent as hidden.

	/**
	*
	* make_add_box Method to Add box with add button and 0 or more editable
	* variable input boxes.  Depending on variables in fieldset, this should
	* support both new records from new primary key, or new multi-column
	* Any record with fieldspec[col]['Add'] will display an edit box also.
	* key records (select keys from other tables for a link table).
	* @param string $addtype  {'new', 'entries'}new = make up new key values, entries = show edit box for keys
	* @param bool $set_to_filter If true (default), filtered values will be passed as seting values.  If False, they wont.
	*
	*/
    function make_add_box($addtype = 'new'){
		// set non_entry values for default of no-value  $addtype is always new, take out sometime
		// CT 2009-10-22 - If you have two keys, just be sure to always specify add.  taking out logic to do it for you
		$none_entry[1]['keyvalue'] = '';
		$none_entry[1]['showvalue'] = '';

        $count = 0;
        $addform .= "<form name='$this->table_name" . "_Add' action='$this->actionpage' method='GET'>\n";
		$addform .= $this->addmarkup;
        foreach($this->fieldspec AS $col_name => $colspec){
		// First, check if filter is set.  If it is, make a hidden add column
			if((!empty($this->filters[$this->filterprefix . $col_name])) OR $this->filters[$this->filterprefix . $col_name] === 0){
				$addform .= "<input type='hidden' name='" . $col_name . "' value='" . $this->filters[$this->filterprefix . $col_name] [val] . "' />\n";
				// may add an overrid for (add form no matter what), but easiest to hard-code form in this case
				}
			else{ 
				// If filter is not set, add a box if 'add' is specified
				if(!empty($colspec['add'])){
				   (empty($colspec['headname']))?$elements[$count] ['head']= $col_name:$elements[$count] ['head']= $colspec['headname'];
				   $elements[$count] ['body'] = MakeEditField($colspec,$this->actval_prefix . $col_name,'', '', $this->actval_prefix . $col_name . '_ADD', $none_entry,$this->top_dir);
				   $count ++; 				
				}
			}
		}

        $elements[$count]['body'] = "<input type='submit' name='mode' value='Add' />";
		$addform .= $this->make_element_set($elements,"class='add_head'","class='add_body'");
		$addform .= "</form>";
	return $addform;

   }


    function OLDmake_add_box($addtype = 'new', $set_to_filter=true){
		// set non_entry values for default of no-value  $addtype is not used
		$none_entry[1]['keyvalue'] = '';
		$none_entry[1]['showvalue'] = '';

        $count = 0;

        $addform .= "<form name='$this->table_name" . "_Add' action='$this->actionpage' method='GET'>";
        foreach($this->fieldspec AS $col_name => $colspec){
            if((!empty($colspec['add']) OR (($addtype == 'entries') AND (!empty($colspec['key'] ))))){
               (empty($colspec['headname']))?$elements[$count] ['head']= $col_name:$elements[$count] ['head']= $colspec['headname'];
               $elements[$count] ['body'] = MakeEditField($colspec,$this->actval_prefix . $col_name,'', '', $this->actval_prefix . $col_name . '_ADD', $none_entry,$this->top_dir);
               $count ++; // below maybe replace with isset 
            } else if((!empty($this->filters[$this->filterprefix . $col_name])) OR $this->filters[$this->filterprefix . $col_name] == 0){
				$addform .= "<input type='hidden' name='" . $col_name . "' value='" . $this->filters[$this->filterprefix . $col_name] [val] . "' />\n";
            } // could replace this with make_add_filter() if if that function proves usefull
		}
        $elements[$count]['body'] = "<input type='submit' name='mode' value='Add' />";
		$addform .= $this->make_element_set($elements,"class='add_head'","class='add_body'");
		$addform .= "</form>";
	return $addform;

   }   
   
   
   /*
	* make_add_filters()  This function will create a hidden input field for use in the add form which sets the variable if it's filter is set
	*
	*/
   function make_add_filter(){
	if((!empty($this->filters[$this->filterprefix . $col_name])) OR $this->filters[$this->filterprefix . $col_name] == 0){
				$addform .= "<input type='hidden' name='" . $col_name . "' value='" . $this->filters[$this->filterprefix . $col_name] [val] . "' />\n";
            }
			return $addform;
   }
	
	/**
	 *
     * get_sort_orders  Method will recieve sort order from $_REQUEST or $_SESSION
     * variables and set the internal variables for use in queries
	 * (Future) - implement this using GetPersistent
	 */
	function get_sort_orders(){
		if(isset($_SESSION[$this->table_name . '_order']) AND $_SESSION[$this->table_name . '_order'] != ''){
			$this->cur_order = $_SESSION[$this->table_name . '_order'];
			$this->cur_dir = $_SESSION[$this->table_name . '_dir'];
			
			$this->orderstring = " ORDER BY $this->cur_order  $this->cur_dir "; 
			
			}
		if(isset($_REQUEST['order']) AND $_REQUEST['order'] != ''){
			$this->new_order = $_REQUEST['order'];
			if($this->new_order == $this->cur_order){ // flip direction if clicked twice
				if($this->cur_dir == 'DESC'){
					$this->cur_dir = 'ASC';
				}
				else{
					$this->cur_dir = 'DESC';
				}
			}// End same order clicked twice
			else{
				$this->cur_order = $this->new_order;
				$this->cur_dir = 'ASC'; // default to asc
			}
		$_SESSION[$this->table_name . '_order'] = $this->cur_order;
		$_SESSION[$this->table_name . '_dir'] = $this->cur_dir;
		
		$this->orderstring = " ORDER BY $this->cur_order  $this->cur_dir "; 
		
	
		} // end order in request
	} // end get sort order


	/**
	 *  make_query_sort  Method will show the 'ORDER BY' query piece.  For Mysql, so far
	 */
	function make_query_sort(){
		$this->get_sort_orders();
		return $this->orderstring;
	
	}

	/**
	 *  get_pagination  Method will recoeve pagination from $_REQUEST and $_SESSION
     * variables and set internal variables for use.  Only call if pagination is used
	 */
	function get_pagination(){
	
		//paging
		if (!empty($_REQUEST[$this->numrowsvar])){
			$this->numrows =  $_REQUEST[$this->numrowsvar];
		}
		else if(isset($_SESSION[$this->table_name . '_numrows'])){
			$this->numrows =  $_SESSION[$this->table_name . '_numrows'];
		}
		else if ($this->default_row_limit != 0) {
			$this->numrows = $this->default_row_limit;
			}
		
		if (isset($_REQUEST[$this->startatvar])){
			$this->startat =  (int)$_REQUEST[$this->startatvar];
			$this->post_rowlimit = " LIMIT $this->startat , $this->numrows ";
			//$this->oracle_post_rowlimit = " ) thequery <= " . $this->startat + $this->numrows;
			//$this->oracle_post_rowlimit .= " ) where rnum >= $this->startat ORDER BY rnum ";
			//$this->pgsql_post_rowlimit = " LIMIT $this->numrows OFFSET $this->startat ";
			//$this->fbird_fix_rowlimit = " FIRST $this->numrows SKIP $this->startat ";
			
			
//print "JUST SET REQUEST startat:	$this->startat <br>";	
		}		
		else if(isset($_SESSION[$this->table_name . '_startat'])){
			$this->startat =  $_SESSION[$this->table_name . '_startat'];
			$this->post_rowlimit = " LIMIT $this->startat , $this->numrows ";
//print "JUST SET SESSION startat:	$this->startat <br>";			
		}else if ($_REQUEST[$this->startatvar] == 'RESET'){ // NOT WORKING
           unset( $_SESSION[$this->table_name . '_startat']);
           unset($_SESSION[$this->table_name . '_numrows']);
           $this->startat = 0;
           $this->numrows = 'MAX';
            unset($this->post_rowlimit);
         }
		else{
			$this->startat = 0;
			$this->post_rowlimit = " LIMIT $this->startat , $this->numrows ";
		}
		

		if(isset($this->post_rowlimit)){
		$_SESSION[$this->table_name . '_numrows'] = $this->numrows;
		$_SESSION[$this->table_name . '_startat'] = $this->startat;
		}
		
//$this->rowsmax = count($array_list);
			//paging calculations
		if(is_null($this->rowsmax)){
			$this->nextpagestart = $this->startat + $this->numrows;
		}
		else{

			if($this->startat + $this->numrows < $this->rowsmax){
				$this->nextpagestart = $this->startat + $this->numrows;
			}
			else{
			$this->nextpagestart = $this->startat;
			}
		}
		
		if($this->startat - $this->numrows > 0){
			$this->prevpagestart = $this->startat - $this->numrows;
			}
		else{
			$this->prevpagestart = 0;
		}
		$this->pageform = "<a href='" . $_SERVER['PHP_SELF'] . "?$this->startatvar=0&$this->numrowsvar=$this->numrows'>First</a>\n";
		$this->pageform .= "<a href='" . $_SERVER['PHP_SELF'] . "?$this->startatvar=$this->prevpagestart&$this->numrowsvar=$this->numrows'>Previous</a>\n";
		$this->pageform .= "<--   -->";
		$this->pageform .= "<a href='" . $_SERVER['PHP_SELF'] . "?$this->startatvar=$this->nextpagestart&$this->numrowsvar=$this->numrows'>Next</a>\n";
		if(!empty($this->rowsmax)){
            // $lastpage = (int)($this->rowsmax / $this->numrows);
            $lastpagestart = $this->rowsmax - $this->numrows;
            if($lastpagestart < 0){
                $lastpagestart = 0;
                }
         $this->pageform .= "<a href='" . $_SERVER['PHP_SELF'] . "?$this->startatvar=$lastpagestart&$this->numrowsvar=$this->numrows'>Last</a>\n"; 
            }
        //print "$this->prevpagestart : $this->nextpagestart : $this->rowsmax <br>";
		//end paging	
	
	}

	
	
}


class CF_EDpage_table extends CFtable{

	var $actionpage;		
	var $editpage;
	var $ordervar = 'order';
	var $allow_delete = true;
	var $allow_edit = true;
    var $edit_link_text = 'Edit';
    var $delete_link_text = 'Delete';
    var $edit_prefix;

	
		
	// New Methods
	
	function set_allow($allowspec){
		if(stristr($allowspec,'d')){
			$this->allow_delete = true;
		}
		else{
			$this->allow_delete = false;
			}
		if(stristr($allowspec,'e')){
			$this->allow_edit = true;
		}		
		else{
			$this->allow_edit = false;
			}		
	}	
	
	
	function set_actionpage($pagename){
		$this->actionpage = $pagename;
	}	
	
	function set_editpage($pagename){
		$this->editpage = $pagename;
	}
	
		
	// Overrides and Extension mehods	
	function make_row_end($row_num){
		if($this->allow_delete){
			$endstring = "<td class='actcell'><a href='$this->actionpage?mode=Delete$this->keys_url_act$referstring'>$this->delete_link_text</a></td>";
			}
		if($this->allow_edit){
			$endstring .= "<td class='actcell'><a href='$this->editpage?mode=Edit$this->keys_url_edit$referstring'>$this->edit_link_text</a></td>";
		}
		$endstring .= "</tr>\n";
		return $endstring;
	}	
}

class CF_InlineEDTable extends CF_EDpage_table {
	

	var $keys_hidden; // keys as hidden fields in form
	var $actionpage; // page form will go to for edit and delete actions
	var $ordervar = 'order';  // set this variable for order when re-ording this query with the headers
	var $oldvalvar = 'OV_';  // This is the prefix for original value in a form

	var $allow_save = true;
	
    var $mode_save = 'Save';
    var $mode_delete = 'Delete';
    var $mode_duplicate = 'Copy';
	var $mode_edit = 'Edit';


	// New Methods
	function set_actionpage($pagename){
		$this->actionpage = $pagename;
	}	
	
	function set_multiselect($value){
		$this->multiselect = $value;
	}
	// overrides

	function set_allow($allowspec){
		if(stristr($allowspec,'d')){
			$this->allow_delete = true;
		}
		else{
			$this->allow_delete = false;
			}
		if(stristr($allowspec,'s')){
			$this->allow_save = true;
		}		
		else{
			$this->allow_save = false;
			}	
		if(stristr($allowspec,'e')){
			$this->allow_edit = true;
		}		
		else{
			$this->allow_edit = false;
			}
			
			// consider adding save and then calling parent::set_allow()			
	}	


	
	function clear_keys_strings() { 
		$this->keys_uid = '';
		$this->keys_hidden = '';
		parent::clear_keys_strings();
	}
	

	

	function make_lookup_value($column,$value){
        $showkey = 'showvalue';
        $valuekey = 'keyvalue';
    	$valuesarray = $this->fieldspec[$column]['list'];
        if(isset($this->fieldspec[$column]['showvalue'])){
            $showkey = $this->fieldspec[$column]['showvalue'];
        }
        if(isset($this->fieldspec[$column]['keyvalue'])){
            $valuekey = $this->fieldspec[$column]['keyvalue'];
        }

        foreach ($valuesarray as $lookup_pair) {
            if($lookup_pair[$valuekey] == $value){
                return $lookup_pair[$showkey];
            }
         }
         return $value;

    }
	
	
	function make_rowval($value,$column){
		
		//$chgname = "chg_$column" . "()";
		
		$row_text .= "<td>";

        $row_text .= $this->make_valuebox($value,$column);

		$row_text .= "</td>";
		return $row_text;
			
	}

   function make_valuebox($value,$column){
      	if($this->fieldspec[$column]['show'] == 'E'){
            $chgname = "validateData" . "('$column', '$this->keys_uid', '$column" . "_" . "$this->keys_uid')";
			//$row_text .= $this->make_editbox($column,$column,$value,$chgname,$column . '_' . $this->keys_uid);
            $row_text .= MakeEditField($this->fieldspec[$column],$column,$value,$chgname,$column . '_' . $this->keys_uid,false,$this->top_dir);
			$ov_name = $this->oldvalvar . $column;
			$row_text .= "<input type='hidden' name='$ov_name' value='$value' id='$ov_name" . "_$this->keys_uid'>";
		}  else if($this->fieldspec[$column]['show'] == 'L') {
            $row_text .= $this->make_lookup_value($column,$value);
        }else {
            $row_text .= "$value";
		}
		return $row_text;
    }


 /**
 * function to make start of row, making each row a form for editing
 * @param int $row_num This is the row number of the dataset
 * @param string $key_string This is the string of key values, defined by make_key_string function
 * @return string Row begining 
 */
	function make_row_start($row_num){
		$formname = $this->tablename . '_' . $this->keys_uid;
		$rowstart .= "<form action='$this->actionpage' name='$formname' method='GET'>";

		$rowstart .= $this->keys_hidden;
		
		if($this->row_status == 'even'){
			$this->row_status = 'odd';
			$rowstart .= "<tr class=\"$this->table_even_class\">";			
		}
		else{
			$this->row_status = 'even';
			$rowstart .= "<tr class=\"$this->table_odd_class\">";			
		}
		
		if($this->multiselect){
			$rowstart .= "<td>" . $this->make_multiselectCB() . "</td>";
		}		
		
		
		
		return $rowstart;
	}


	function make_row_end($row_num){
		if($this->allow_save){
			$rowend .= "<td class='actsave'><input type='submit' name='mode' value='" . $this->mode_save . "'></td>";
		}
		if($this->allow_delete){
			$rowend .= "<td class='actdel'><input type='submit' name='mode' value='" . $this->mode_delete . "'></td>";
			}
		if($this->allow_edit){
			$rowend .= "<td class='actedit'><input type='submit' name='mode' value='" . $this->mode_edit . "'></td>";
			}			
			
		$rowend .= "</tr></form>\n";
		
		return $rowend;
	}
	
}// end Class CF_InlineEDTable

class CF_AJTable extends CF_InlineEDTable{
	
	

	function make_rowval($value,$column){
		
		$chgname = "syncVal" . "('$column', '$this->keys_uid', '$column" . "_" . "$this->keys_uid')";
		
		$row_text .= "<td>";
        $row_text .= $this->make_valuebox($value,$column);
        $row_text .= "</td>";
		return $row_text;
			
	}


    function make_valuebox($value,$column){
      	if($this->fieldspec[$column]['show'] == 'E'){
            $chgname = "syncVal" . "('$column', '$this->keys_uid', '$column" . "_" . "$this->keys_uid')";
			//$row_text .= $this->make_editbox($column,$column,$value,$chgname,$column . '_' . $this->keys_uid);
            $row_text .= MakeEditField($this->fieldspec[$column],$column,$value,$chgname,$column . '_' . $this->keys_uid,false,$this->top_dir);
			$ov_name = $this->oldvalvar . $column;
			$row_text .= "<input type='hidden' name='$ov_name' value='$value' id='$ov_name" . "_$this->keys_uid'>";
		}  else if($this->fieldspec[$column]['show'] == 'L') {
            $row_text .= $this->make_lookup_value($column,$value);
        }else {
            $row_text .= "$value";
		}
		return $row_text;
    }

	function make_row_end($row_num){
		if($this->allow_save){
			$rowend .= "<td class='actsave'><input type='submit' name='mode' value='" . $this->mode_save . "'></td>";
		}
		if($this->allow_delete){
			$rowend .= "<td class='actdel'><input type='submit' name='mode' value='" . $this->mode_delete . "'></td>";
			}
		if($this->allow_edit){
			$rowend .= "<td class='actedit'><input type='submit' name='mode' value='" . $this->mode_edit . "'></td>";
			}			
		$rowend .= "</tr></form>\n";
		
	return $rowend;
	}

}


